<?php
/*
 * To change this template, choose Tools | Templates and open the template in the editor.
 *
 *
 */
//Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/js/jquery-1.7.1.min.js', CClientScript::POS_HEAD);
//
//if ($model->avatar != null) {
//    echo '<img width="80px" src="' . Yii::app()->baseUrl . '/upload/user/' . $model->id . '/avatar/' . $model->avatar . '"><br>';
//}
//echo $model->email . '<br>';
//echo $model->username . '<br>';
//echo $model->fullname . '<br>';
//echo 'Collection : ' . CHtml::link(sizeof($collections), array('collection/user', 'username' => $model->username)) . '<br>';
//if (Yii::app()->user->id == $model->id) {
//    echo '<a href="' . Yii::app()->createUrl('user/edit') . '">Sửa</a><br>';
//    if (User::model()->getRole(Yii::app()->user->id) == 'vip') {
//        echo '<a href="' . Yii::app()->createUrl('blog/create') . '">Viết Blog</a><br>';
//    }
//}
//if (!Yii::app()->user->isGuest) {
//    if (Yii::app()->user->id != $model->id) {
//        $checkFollow = UserFollow::model()->find("followed = :followed and follower =:follower", array(
//            ':followed' => $model->id,
//            'follower' => Yii::app()->user->id
//        ));
//        if ($checkFollow) {
//            
?>
<!--<a href="#" class="follow_link" onclick="return follow();">Bỏ theo dõi</a>-->
<?php
//        } else {
//            
?>
<!--<a href="#" class="follow_link" onclick="return follow();">Theo dõi</a>-->
<?php
//        }
//    }
//}
?>
<hr>
<script type="text/javascript">
    function follow(id) {
        $.ajax({
            url: "<?php echo Yii::app()->createUrl('user/follow') . '?id='; ?>" + id,
            type: 'GET',
            success: function(data) {
                $("a#user_" + id).text(data);
            }
        });
        return false;
    }

    function like(id) {
        $.ajax({
            url: "<?php echo Yii::app()->createUrl('image/like') . '?id='; ?>" + id,
            type: 'GET',
            success: function(data) {
                var json = eval('(' + data + ')');
                $("a.like_link_" + id).text(json['meg']);
                $("p.like_cnt_" + id).text(json['like_cnt']);
            },
        });
        return false;
    }
</script>
<!--<div id="dialogWrapper"></div>-->
<?php
//if ($image != null) {
//    foreach ($image as $i) {
//        echo '<a href="' . Yii::app()->createUrl('image/view', array(
//            'id' => $i->id
//        )) . '">' . $i->title . '</a><br>';
//        echo 'Lượt xem : ' . $i->view_cnt . '<br>';
//        echo 'Lượt thích : <p class="like_cnt_' . $i->id . '">' . $i->like_cnt . '</p><br>';
//        $checkLike = ImageLike::model()->find("user_id = :user_id and image_id =:image_id", array(
//            ':image_id' => $i->id,
//            'user_id' => Yii::app()->user->id
//        ));
//        if ($checkLike) {
//            
?>
<!--            <a href="#" class="like_link_//<?php // echo $i->id;      ?>"
               onclick=" return like(//<?php // echo $i->id;      ?>);">Bỏ thích</a>-->
<?php
//           } else {
//               
?>
<!--            <a href="#" class="like_link_//<?php // echo $i->id;      ?>"
               onclick="return like(//<?php // echo $i->id;      ?>);">Thích</a>-->
<?php
//}
//           echo '<img width="150px" src="' . Yii::app()->baseUrl . '/upload/user/' . $i->userCreated->id . '/images/' . $i->img_url . '" /><br><hr>';
//       }
//   } else {
//       echo 'Bạn chưa đăng ảnh nào.';
//   }
?>

<!-- main home -->
<div id="main">
    <div id="main_content" class="page_view">
        <!-- view -->
        <!-- col left -->
        <div class="col_left">
            <div class="user_page">
                <div class="up_cover">
                    <img src="<?php echo Yii::app()->baseUrl . '/images/demo/cover.jpg'; ?>" border="0" />
                </div>
                <div class="up_info">
                    <div class="avatar"><img src="<?php echo Yii::app()->baseUrl . '/upload/user/' . $model->id . '/avatar/' . $model->avatar; ?>" alt="#" border="0" /></div>
                    <div class="upi_name"><h2><?php echo $model->fullname; ?></h2></div>
                    <div class="upi_desc">
                        <div class="fll">
                            <span>"King of street"</span>
                            <?php
                            $checkFollow = UserFollow::model()->find("followed = :followed and follower =:follower", array(
                                ':followed' => $model->id,
                                'follower' => Yii::app()->user->id
                            ));

                            if (!$checkFollow && Yii::app()->user->id != null && Yii::app()->user->id != $model->id) {
                                ?>
                                <p class="mt10"><a id="user_<?php echo $model->id; ?>" onclick="return follow(<?php echo $model->id; ?>);" class="btn_follow" href="#">Theo dõi</a></p>
                            <?php } if ($checkFollow && Yii::app()->user->id != null && Yii::app()->user->id != $model->id) { ?>
                                <p class="mt10"><a id="user_<?php echo $model->id; ?>" onclick="return follow(<?php echo $model->id; ?>);" class="btn_follow" href="#">Bỏ theo dõi</a></p> 
                            <?php } ?>
                        </div>
                        <div class="flr">
                            <div class="c_l_t_share">
                                <div class="content">
                                    CHIA SẺ
                                    <p>
                                        <a class="share_icons share_icons_fb" title="Facebook" href="#"></a>
                                        <a class="share_icons share_icons_tw" title="Twitter" href="#"></a>
                                        <a class="share_icons share_icons_tr" title="Tumblr" href="#"></a>
                                        <a class="share_icons share_icons_pin" title="Pinterest" href="#"></a>
                                    </p>
                                    <p><img border="0" src="<?php echo Yii::app()->baseUrl . '/images/like_demo.png'; ?>"></p>
                                </div>
                            </div>
                        </div>
                        <div class="clr"></div>
                    </div>
                </div>
                <div class="up_about">
                    <h5>Về <?php echo $model->fullname; ?></h5>
                    <div class="content">
                        Tôi là người sống biết điều trong showbiz. Tôi không thể tự mãn về thành công của mình được, nếu có thì đó là lúc tôi soi gương ở trong ngôi nhà của chính mình. Bất cứ ai cũng có vài phút kiêu căng về bản thân nhưng điều quan trọng là họ có thể hiện điều đó hay không. Đi cùng bạn bè, tôi tự tin mình có thể hát được bao nhiêu bài cho họ nghe, nhưng đứng trước đám đông, tôi luôn kìm bản thân mình lại. Tôi từng hỏi rất nhiều anh chị đi trước và lắng nghe họ để học hỏi những điều hay.
                        <div class="s_ab_wrap">
                            <a href="#" class="s_ab"><span class="share_icons share_icons_fb"></span>Facebook.com/miakimcon</a>
                            <a href="#" class="s_ab"><span class="share_icons share_icons_tr"></span>MiaKim.tumblr.com/</a>
                            <a href="#" class="s_ab"><span class="share_icons share_icons_pin"></span>Pinterest.com/miakim</a>
                        </div>
                    </div>
                </div>
                <!-- block collection -->
                <div class="block_collection">
                    <h5>Bộ sưu tập</h5>
                    <?php
                    if ($collections == null) {
                        echo 'Chưa có bộ sưu tập nào.';
                    } else {
                        foreach ($collections as $collection) {
                            $topimage = Yii::app()->db->createCommand()->select('i.*')->from('tbl_image i')->join('tbl_collection_image ci', 'ci.image_id=i.id')->where('ci.collection_id=:id and i.status=:status', array(':id' => $collection->id, ':status' => Image::IMAGE_ACTIVE))->limit('1')->order('(like_cnt * 5 + view_cnt) DESC')->queryRow();
                            ?>
                            <div class="c_r_c_li">
                                <div class="c_r_c_li_thumb"><a title="<?php echo $collection->name; ?>" href="<?php echo Yii::app()->createUrl('collection/view', array('id' => $collection->id)) ?>"><img width="120px" border="0" alt="<?php echo $collection->name; ?>" title="<?php echo $collection->name; ?>" src="<?php echo Yii::app()->baseUrl . '/upload/user/' . $topimage['user_created'] . '/images/' . $topimage['img_url']; ?>"></a></div>
                                <div class="c_r_c_li_info">
                                    <a title="<?php echo $collection->name; ?>" href="#"><h1><?php echo $collection->name; ?></h1></a>
                                    <!--<a title="Lyzmary" href="#"><h2>Lyzmary</h2></a>-->
                                    <p><span class="sprites like_icon"></span>322</p>
                                    <p><span class="sprites collection_icon"></span>16 ảnh</p>
                                </div>
                            </div>
                            <?php
                        }
                    }
                    ?>
                    <div class="clr"></div>
                    <!--<div class="more"><a href="#" title="Xem thêm">Xem thêm</a></div>-->
                </div>
                <!--/ block collection -->
                <!-- block photos -->
                <div class="block_photos">
                    <h5>Ảnh của <?php echo $model->fullname; ?></h5>
                    <?php
                    if ($image != null) {
                        foreach ($image as $i) {
                            ?>
                            <div class="bp-li">
                                <div class="fll"><a href="<?php echo Yii::app()->createUrl('image/view', array('id' => $i->id)); ?>"><img class="thumb" src="<?php echo Yii::app()->baseUrl . '/upload/user/' . $i->user_created . '/images/' . $i->img_url; ?>" border="0" alt="#" /></a></div>
                                <div class="flr">
                                    <a href="<?php echo Yii::app()->createUrl('image/view', array('id' => $i->id)); ?>"><h1><?php echo $i->title; ?></h1></a>
                                    <p><span class="sprites like_icon"></span><?php echo $i->like_cnt; ?></p>
                                    <p><span class="sprites comment_icon"></span><?php echo sizeof(Comment::model()->findAll('image_id=:id', array(':id' => $i->id))); ?></p>
                                    <a href="#" class="icon_like_b"></a>
                                    <div class="icon_save_b save_collect_idphoto">
                                        <div class="save_box save_box_idphoto">
                                            <ul class="content">
                                                <li class="sb_title">BỘ SƯU TẬP<div title="Đóng" class="save_collect_idphoto"></div></li>
                                                <li><a href="#" title="#">Xinh tươi cùng gió<span>(16)</span></a></li>
                                                <li><a href="#" title="#">Blue Cheetah Print<span>(9)</span></a></li>
                                                <li><a href="#" title="#">WHITE PRETTY SANDALS & SKORTS<span>(11)</span></a></li>
                                            </ul>
                                            <div class="sb_div">
                                                <input type="text" placeholder="Tạo BST mới" class="sb_input" name="Collection" />
                                                <input type="submit" class="gr_btn_normal" value="Tạo" />
                                            </div>
                                        </div>
                                        <style type="text/css">
                                            .active .save_box_idphoto{ display: block;}
                                        </style>

                                    </div>
                                </div>
                                <div class="clr"></div>
                            </div>
                            <?php
                        }
                    } else {
                        if ($model->id == Yii::app()->user->id) {
                            echo 'Bạn chưa có ảnh nào, hãy ' . CHtml::link('đăng ảnh', array('image/upload')) . ' ngay thôi nào :)';
                        } else {
                            echo 'Chưa có ảnh nào.';
                        }
                    }
                    ?>
<!--                    <script type="text/javascript">
$(document).ready(function() {
$(".save_collect_idphoto").click(function(e) {
e.preventDefault();
$(".save_collect_idphoto").toggleClass("active");
});
$(".save_box").click(function(e) {
e.preventDefault();
$(".save_collect_idphoto").toggleClass("active");
});
});
</script>-->
                    <!--<div class="more"><a href="#" title="Xem thêm">Xem thêm</a></div>-->
                </div>
                <!-- / block photos -->
            </div>
        </div>
        <!-- / col left -->
        <!-- col right -->
        <div class="col_right">
            <!-- may know -->
            <div class="col_right_people col_right_user">
                <h5>Danh sách theo dõi</h5>
                <div class="content">
                    <?php
                    if ($userFollow != null) {
                        foreach ($userFollow as $uf) {
                            ?>
                            <div class="c_r_p_li">
                                <div class="d_avatar mr10 fll"><a href="<?php echo Yii::app()->createUrl('user/view', array('username' => $uf->username)); ?>"><img border="0" src="<?php echo Yii::app()->baseUrl . '/upload/user/' . $uf->id . '/avatar/' . $uf->avatar; ?>" class="d_avatar" /></a></div>
                                <div class="c_r_p_li_info">
                                    <a href="user.html" class="member_name"><?php echo $uf->fullname; ?></a>
                                    <p>232 người theo dõi</p>
                                    <p>Bộ sưu tập: 7</p>
                                </div>
                                <?php
                            $checkFollow = UserFollow::model()->find("followed = :followed and follower =:follower", array(
                                ':followed' => $uf->id,
                                'follower' => Yii::app()->user->id
                            ));

                            if (!$checkFollow && Yii::app()->user->id != null) {
                                ?>
                                <a id="user_<?php echo $uf->id; ?>" onclick="return follow(<?php echo $model->id; ?>);" class="btn_follow" href="#">Theo dõi</a>
                            <?php } if ($checkFollow && Yii::app()->user->id) { ?>
                                <a id="user_<?php echo $uf->id; ?>" onclick="return follow(<?php echo $model->id; ?>);" class="btn_follow" href="#">Bỏ theo dõi</a>
                            <?php } ?>
                            </div>
                            <?php
                        }
                    }
                    ?>
                </div>
            </div>
            <!-- / may know -->
            <!-- top photos -->
            <div class="col_right_photo mt20" style="border-top: 1px solid #ccc; padding-top: 20px;">
                <h5>Top ảnh đẹp</h5>
                <div class="col_right_collect">
                    <div class="c_r_c_li">
                        <div class="c_r_c_li_thumb"><a title="Xinh tươi cùng gió" href="collection.html"><img border="0" alt="Xinh tươi cùng gió" title="Xinh tươi cùng gió" src="<?php echo Yii::app()->baseUrl . '/images/demo/collect_3.jpg'; ?>"></a></div>
                        <div class="c_r_c_li_info">
                            <a title="Xinh tươi cùng gió" href="#"><h1>Xinh tươi cùng gió</h1></a>
                            <a title="Lyzmary" href="#"><h2>Lyzmary</h2></a>
                            <p><span class="sprites like_icon"></span>322</p>
                            <p><span class="sprites comment_icon"></span>16</p>
                        </div>
                    </div>
                    <div class="c_r_c_li">
                        <div class="c_r_c_li_thumb"><a title="Blue Cheetah Print" href="collection.html"><img border="0" alt="Blue Cheetah Print" title="Blue Cheetah Print" src="<?php echo Yii::app()->baseUrl . '/images/demo/collect_2.jpg'; ?>"></a></div>
                        <div class="c_r_c_li_info">
                            <a title="Xinh tươi cùng gió" href="#"><h1>Blue Cheetah Print</h1></a>
                            <a title="Lyzmary" href="#"><h2>Lyzmary</h2></a>
                            <p><span class="sprites like_icon"></span>322</p>
                            <p><span class="sprites comment_icon"></span>16</p>
                        </div>
                    </div>
                    <div class="c_r_c_li">
                        <div class="c_r_c_li_thumb"><a title="Sea side strolling " href="collection.html"><img border="0" alt="Sea side strolling" title="Sea side strolling" src="<?php echo Yii::app()->baseUrl . '/images/demo/collect_1.jpg'; ?>"></a></div>
                        <div class="c_r_c_li_info">
                            <a title="Sea side strolling" href="#"><h1>Sea side strolling</h1></a>
                            <a title="Lyzmary" href="#"><h2>Lyzmary</h2></a>
                            <p><span class="sprites like_icon"></span>322</p>
                            <p><span class="sprites comment_icon"></span>16</p>
                        </div>
                    </div>
                    <div class="c_r_c_li">
                        <div class="c_r_c_li_thumb"><a title="WHITE PRETTY SANDALS &amp; SKORTS" href="collection.html"><img border="0" alt="WHITE PRETTY SANDALS &amp; SKORTS" title="WHITE PRETTY SANDALS &amp; SKORTS" src="<?php echo Yii::app()->baseUrl . '/images/demo/collect_4.jpg'; ?>"></a></div>
                        <div class="c_r_c_li_info">
                            <a title="WHITE PRETTY SANDALS &amp; SKORTS" href="#"><h1>WHITE PRETTY SANDALS &amp; SKORTS</h1></a>
                            <a title="Lyzmary" href="#"><h2>Lyzmary</h2></a>
                            <p><span class="sprites like_icon"></span>322</p>
                            <p><span class="sprites comment_icon"></span>16</p>
                        </div>
                    </div>
                </div>
            </div>
            <!-- / top photos -->
        </div>
        <!-- / col right -->
        <div class="clr"></div>
        <!-- end view -->
    </div>
</div>
<!-- main home -->
